<template>
	<el-container>
		<el-aside width="200px" v-loading="showGrouploading">
			<el-container>
				<el-header>
					<el-input placeholder="输入关键字进行过滤" v-model="groupFilterText" clearable></el-input>
				</el-header>
				<el-main class="nopadding">
					<el-tree ref="archivesSort" class="menu" node-key="sortId" :data="sortList" :props="groupsProps" :current-node-key="''" :highlight-current="true" :expand-on-click-node="false"
							 :filter-node-method="groupFilterNode" @node-click="groupClick">
						<template #default="{node, data}">
							<span class="custom-tree-node">
								<span class="label">{{ node.label }}</span>
								<span class="code">{{ data.code }}</span>
							</span>
						</template>

					</el-tree>
				</el-main>
			</el-container>
		</el-aside>
		<el-container>
			<el-header style="height: auto;">
				<sc-select-filter :data="filterData" :label-width="80" @on-change="filterChange"></sc-select-filter>
			</el-header>
			<el-header>
				<div class="left-panel">
				</div>
				<div class="right-panel">
					<div class="right-panel-search">
						<el-input v-model="search.keyword" placeholder="标题 / 摘要" clearable></el-input>
						<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
					</div>
				</div>
			</el-header>
			<el-main class="nopadding">
				<scTable ref="table" :apiObj="apiObj" :params="this.search" row-key="recordId" stripe remoteSort>
					<el-table-column label="#" type="index" width="50"></el-table-column>
					<el-table-column label="档案标题" prop="title" width="200" :show-overflow-tooltip="true"></el-table-column>
					<el-table-column label="档案分类" prop="sortName" width="150"></el-table-column>
					<el-table-column label="是否实物" prop="isKind" width="100">
						<template #default="scope">
							<el-tag type="warning" effect="dark" v-if="scope.row.isKind=='0'">电子</el-tag>
							<el-tag type="success" effect="dark" v-if="scope.row.isKind=='1'">实物</el-tag>
							<el-tag type="info" effect="dark" v-if="scope.row.isKind=='2'">并存</el-tag>
						</template>
					</el-table-column>
					<el-table-column label="当前状态" prop="status" width="100">
						<template #default="scope">
							<el-tag type="warning" effect="dark" v-if="scope.row.status=='0'">未归档</el-tag>
							<el-tag type="success" effect="dark" v-if="scope.row.status=='1'">已归档</el-tag>
						</template>
					</el-table-column>
					<el-table-column label="文件数量" prop="fileQuantity" width="100">
						<template #default="scope">
							{{scope.row.fileQuantity}}/份
						</template>
					</el-table-column>
					<el-table-column label="页数" prop="pages" width="100">
						<template #default="scope">
							{{scope.row.pages}}/页
						</template>
					</el-table-column>
					<el-table-column label="文件格式" prop="extName" width="150"></el-table-column>
					<el-table-column label="操作" fixed="right" align="right" width="170">
						<template #default="scope">
							<el-button-group>
								<el-button text type="primary" size="small" @click="table_show(scope.row, scope.$index)">查看</el-button>
								<el-button text type="primary" size="small" @click="table_edit(scope.row, scope.$index)" v-if="scope.row.borrowingFlag=='1'">借阅</el-button>
							</el-button-group>
						</template>
					</el-table-column>
				</scTable>
			</el-main>
		</el-container>
	</el-container>
	<save-dialog v-if="dialog.save" ref="saveDialog" @success="handleSuccess" @closed="dialog.save=false"></save-dialog>
	<recordDetails v-if="dialog.detailsSave" ref="detailsDialog" @closed="dialog.detailsSave=false"></recordDetails>
</template>
<script>
import saveDialog from "./save";
import scSelectFilter from '@/components/scSelectFilter'
import recordDetails from './details'
export default {
	name: 'Archives Search By Sort',
	components: {
		scSelectFilter,
		recordDetails,
		saveDialog
	},
	data() {
		return {
			filterData: [
				{
					title: "日期范围",
					key: "date",
					multiple: false,
					options: [
						{
							label: "全部",
							value: ""
						},
						{
							label: "今日",
							value: "1"
						},
						{
							label: "昨日",
							value: "2"
						},
						{
							label: "一周内",
							value: "3"
						},
						{
							label: "一月内",
							value: "4"
						},
						{
							label: "一月前",
							value: "5"
						}
					]
				},
				{
					title: "涉密等级",
					key: "classifiedLevel",
					multiple: false,
					options:[{
						label: "全部",
						value: ""
					}]
				},
			],
			apiObj: this.$API.archives.archivesRecord.getArchivesRecordListBySort,
			dialog: {
				detailsSave:false,
				save:false
			},
			showGrouploading: false,
			groupFilterText: '',
			fileList:[],
			sortList: [],
			groupsProps: {
				label: "name",
				value: "sortId"
			},
			search: {
				date:'',
				sortId:"",
				classifiedLevel:"",
				keyword: ""
			}
		}
	},
	watch: {
		groupFilterText(val) {
			this.$refs.archivesSort.filter(val);
		}
	},
	mounted() {
		this.getArchivesSmLevelByCode();
		this.getArchivesSortTree()
	},
	methods: {
		async getArchivesSmLevelByCode()
		{
			var res = await this.$API.archives.archivesDic.getArchivesDicByCode.get({code:'archivesSmLevel'});
			if (res.code == 200) {
				this.filterData[1].options=this.filterData[1].options.concat(res.data);
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		//加载树数据
		async getArchivesSortTree() {
			this.showGrouploading = true;
			var res = await this.$API.archives.archivesSort.getArchivesSortTree.get();
			this.showGrouploading = false;
			this.sortList = res.data;
		},
		filterChange(data){
			this.search.date = data.date;
			this.search.sortId = data.sortId;
			this.search.classifiedLevel = data.classifiedLevel;
			this.$refs.table.upData(this.search)
		},
		//树过滤
		groupFilterNode(value, data) {
			if (!value) return true;
			return data.name.indexOf(value) !== -1;
		},
		//树点击事件
		groupClick(data) {
			this.sortId = data.sortId
			this.search.sortId = data.sortId
			this.$refs.table.upData(this.search)
		},
		//本地更新数据
		handleSuccess(data, mode) {
			this.$refs.table.refresh();

		},
		table_edit(row,index)
		{
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open().setData(row)
			})
		},
		table_show(row,index)
		{
			this.dialog.detailsSave = true
			this.$nextTick(() => {
				this.$refs.detailsDialog.open().setData(row)
			})
		},
		//搜索
		upsearch() {
			this.$refs.table.upData(this.search)
		},
	}
}
</script>
<style scoped>
.custom-tree-node {
	/*display: flex;*/
	flex: 1;
	align-items: center;
	justify-content: space-between;
	font-size: 14px;
	padding-right: 24px;
	height: 100%;
}

.custom-tree-node .code {
	font-size: 12px;
	color: #999;
}

.custom-tree-node .do {
	margin-left: 10px;
	display: none;
}

.custom-tree-node:hover .code {
	display: none;
}

.custom-tree-node:hover .do {
	margin-left: 10px;
	display: inline-block;
}
</style>
